<template>
  <div class="box">
    <el-form
      :model="ruleForm"
      :inline="false"
      :rules="rules"
      ref="ruleForm"
      label-width="220px"
      class="demo-ruleForm"
      size="medium"
    >
      <!-- <h2 class="tle">业务申请信息填写</h2> -->
      <div class="must">
        <!-- <el-form-item label="联系人：" prop="contacts">
          <el-input v-model="ruleForm.contacts" placeholder="请填写联系人"></el-input>
          <div class="inform">
              <img src="../../assets/imgs/inform.png" alt="通知" />
              <div class="content">
                <span>示例：王五</span>
              </div>
            </div>
        </el-form-item> -->
        <el-form-item label="商标注册/申请号：" prop="appCode">
          <el-input v-model="ruleForm.appCode" placeholder="请填写原商标申请号"></el-input>
          <div class="inform">
              <img src="../../assets/imgs/inform.png" alt="通知" />
              <div class="content">
                <span>示例：2515783543</span>
              </div>
            </div>
        </el-form-item>
        <!--<el-form-item label="原商标注册/申请号：">-->
        <!--<el-input v-model="ruleForm.codeCredit" placeholder="请填写原商标申请号"></el-input>-->
        <!--</el-form-item>-->
        <el-form-item label="申请补正理由：" prop="reasons">
          <el-input type="textarea" v-model="ruleForm.reasons" placeholder="请填写申请补正理由"
          style="width:80%"
          ></el-input>
        </el-form-item>
        <el-form-item class="upload" label="网上确认书：" prop="qrfile_status">
          <span id="star">*</span>
          <!-- <upfile :callback="setSure"></upfile> -->
          <upfile :callback="setSure">
            <img :src="old_imgs['qrfile']" v-if="old_imgs['qrfile']" style="width:148px;height:148px;margin-bottom:10px" />
          </upfile>
          <div class="exam-img">
              <div class="img-inform">
                  <img src="../../assets/imgs/inform.png">
                  <span>示例:</span>
              </div>
              <examimg :imgType="4"></examimg>
          </div>
          <div>
            <span class="informs">
              请点此
              <a :href="mconfig.host + '/file/download?fileType=2'"
                >下载网上确认书</a
              >,查到相应商标编号并填充
            </span>
            <br />
            <span class="notice"
              >请将下载的网上确认书填写完成, 然后上传JPG文件或是PNG文件</span
            >
          </div>
        </el-form-item>
        <el-form-item label="其他附件：">
          <uploads
              :callback="backUrl"
              :delUrl="delUrl"
              :file_config="{field:'dengjichenluofile'}"
              :list="ruleForm.dengjichenluofile"></uploads>
          <div class="inform" style="margin-left: 70px">
            <img src="../../assets/imgs/inform.png" alt="通知" />
            <div class="content">
              <span>提示：其他附件</span>
            </div>
          </div>
        </el-form-item>
        <el-form-item>
          <div class="btns">
            <el-button type="primary" @click="outStep">上一步</el-button>
            <el-button type="primary" @click="submitCheck('ruleForm')">提交并审核</el-button>
          </div>
        </el-form-item>
        <el-dialog
          class="dialog"
          :show-close="false"
          :center="true"
          :visible.sync="dialogVisible"
          width="460px"
          :before-close="handleClose"
        >
          <div class="hint">
            <img src="../../assets/imgs/branch.png" alt="提示图片" />
            <span>选择您想去办理的网点</span>
          </div>
          <el-form-item label="选择网点：" prop="value" >
              <el-select style="margin-left:-10px" v-model="ruleForm.branchNetworkId" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.deptId"
                  :label="item.deptName"
                  :value="item.deptId"
                >
                  <span style="float: left">{{ item.deptName }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.address }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          <div slot="footer" class="dialog-footer">
            <el-button type="info" @click="dialogVisible = false"
              >取 消</el-button
            >
            <el-button type="primary" @click="submitForm('ruleForm')"
              >确 定</el-button
            >
          </div>
        </el-dialog>
        <el-dialog
          class="hintMsg"
          :show-close="false"
          title="温馨提示"
          :visible.sync="centerDialogVisible"
          @close="skip()"
          width="462px"
        >
          <span
            >您的信息已提交，工作人员将在3-5日内对你的信息审核，审核通过后即可预约业务，审核结果将通过短信的方式发送给你。</span
          >
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="skip">确 定</el-button>
          </span>
        </el-dialog>
      </div>
    </el-form>
  </div>
</template>
<script>
import BaseUpload from "./BaseUpload";
import upfile from "../common/upfile.vue";
import examimg from "../common/imgExample";
import uploads from "@/components/common/uploads";
export default {
  data() {
    return {
      uploadImg: false,
      //网点列表
      options: [],
      //提交成功弹出框变量
      centerDialogVisible: false,
      //网点弹出框控制变量
      dialogVisible: false,

      // add:0,
      //表单唯一id
      classId: "",
      //填写的信息
      ruleForm: {
        // contacts: "",
        // nameAgen: "",
        //        codeCredit: "",
        reasons: "",
        branchNetworkId: "",
        appCode: "",
        qrfile:'',
        qrfile_status: "", //用来确定图片字段是否为空
        dengjichenluofile:[], // 其他附件
      },
      rules: {
        // 其他附件
        dengjichenluofile: [
          { required: true, message: "附件不能为空", trigger: "change" },
        ],
        // contacts: [
        //   { required: true, message: "请填写联系人", trigger: "blur" },
        //   {
        //     pattern: /[\u4e00-\u9fa5]/,
        //     message: "联系人只能为中文",
        //     trigger: "blur",
        //   },
        //   {
        //     min: 2,
        //     max: 20,
        //     message: "联系人长度在2到5个字符之间",
        //     trigger: "blur",
        //   },
        // ],
        appCode: [
          {
              required: true,
              message: "请输入注册号",
              trigger: "blur",
          },
          {
              pattern: /^[A-Za-z0-9]{0,30}$/,
              message: "请输入正确的注册号",
              trigger: "blur",
          },
        ],
        reasons: [
          { required: true, message: "请填写申请补正理由", trigger: "blur" },
          {
            min: 0,
            max: 255,
            message: "申请理由在0到255个字符之间",
            trigger: "blur",
          },
        ],
        // qrfile_status: [
        //   { required: true, message: "请上传网上确认书", trigger: "blur" },
        // ],
      },
      old_imgs: {
        qrfile: "",
      },
    };
  },
  mounted() {
    //获取从存储在路由中的classId
    this.classId = this.$route.query.id;
    //获取网点列表
    this.$http.get("/trademark/system/dept/findDept").then((res) => {
      this.options = res.data.data;
    });
    /* ********************************************修改数据start******************************************* */
    if (this.$store.state.alterData.public) {
      this.uploadImg = true
      let formDa = {};
      Object.assign(
        formDa,
        this.$store.state.alterData.data,
        this.$store.state.alterData.public
      );
      let {
        // contacts,
        nameAgen,
        reasons,
        appCode,
        file,
        branchNetworkId,
        qrfile,
        otherfile,
      } = formDa;

      // 其他附件
      this.ruleForm.dengjichenluofile = JSON.parse(otherfile);
      // this.ruleForm.contacts = contacts;
      this.ruleForm.nameAgen = nameAgen;
      this.ruleForm.reasons = reasons;
      this.ruleForm.appCode = appCode;
      this.ruleForm.branchNetworkId = JSON.parse(branchNetworkId);
      if (qrfile) {
        this.ruleForm.qrfile_status = "1";
        this.old_imgs.qrfile = this.mconfig.host + qrfile;
      }
      if (file) {
        this.old_imgs.file = this.mconfig.host + file;
      }
      this.ruleForm.commonArr = this.$store.state.alterData.append;
    }
    /* ********************************************修改数据end******************************************* */
  },
  methods: {
    backUrl(url,file_config){
      this.ruleForm[file_config["field"]].push(url)
    },
    delUrl(index,file_config){
      this.ruleForm[file_config["field"]].splice(index,1)
      this.$set(this.ruleForm,file_config["field"],this.ruleForm[file_config["field"]])
    },

    //返回上一步
    outStep() {
      this.$emit("wp", 1, "请填写申请业务信息");
    },
    //提示模板
    open1(msg, types = "success") {
      this.$message({
        message: msg,
        type: types,
      });
    },
    //弹出框的选项确认框
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    //表单提交事件
    submitForm(formName) {
      let _this = this;
      if (this.ruleForm.branchNetworkId === "") {
        this.$message({
          type: "error",
          message: "请选择网点",
        });
        return;
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          //每次提交重新生成新的FormData用于储存新的数据
          var formData = new FormData();
          this.dialogVisible = false;

          let arr = this.$store.getters.getRuleForm;
          for (let key in arr) {
            formData.append(key, arr[key]);
          }


          formData.append("appCode", this.ruleForm.appCode); //商标注册号
          // formData.append("appName", names); //申请人名称
          // formData.append("appliType", person_type); //申请人类型(0企业1个人)
          formData.append("branchNetworkId", this.ruleForm.branchNetworkId); //网点编号
          formData.append("classId", this.$route.query.id); //本条记录对应业务在24种业务表里的编号
          // formData.append("contacts", this.ruleForm.contacts); //联系人
          formData.append("nameAgen", this.ruleForm.nameAgen); //代理机构名称
          formData.append("qrfile", ""); //确认书
          formData.append("qrfiles", this.ruleForm.qrfile || {}); //网上确认书(文件流对象) (可选)
          formData.append("reasons", this.ruleForm.reasons); //申请补证理由
          // formData.append("remarks", remarks); //备注 (可选)
          // 其他附件
          formData.append('otherfile', JSON.stringify(this.ruleForm.dengjichenluofile));
          //请求地址
          let urls = "";
          if (this.$store.state.alterData.public) {
            formData.append("id", this.$store.state.alterData.public.id);
            urls = "trademark/proTReissue/modifyNoCommit";
          } else {
            urls = "trademark/proTReissue/firstSubmit";
          }
          //配置请求头
          var config = {
            header: {
              "Content-Type": "multipart/form-data",
            },
          };
          this.$http
            .post(urls, formData, config)
            .then(function(response) {
              //////console.log(response);
              //若状态码不为200则不跳转v bvb vvccvb vbvbcgvbc
              if (response.data.code != 200) {
                _this.open1("提交失败", "error");
                return;
              }
              //提交成功
              _this.centerDialogVisible = true;
              this.$store.commit("storeDatas", {});
              this.$store.commit("setPicType", 0);
              this.$store.commit("setCompanyCardInfo", {});
              this.$store.commit("setIdCardInfo", {});
            })
            .catch(function(error) {
              //////console.log(error);
            });
        } else {
          return false;
        }
      });
    },
    //跳转函数
    skip() {
      this.centerDialogVisible = false;
      this.open1("操作成功");
      this.$router.push({
        path: "/business/myBusiness/auditing",
      });
    },
    //重置表单函数(没用上)
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //确认书
    // setSure(files) {
    //   if (files.length > 0) {
    //     this.ruleForm.qrfile_status = "1";
    //   } else {
    //     this.ruleForm.qrfile_status = "";
    //   }
    //   this.ruleForm.qrfile = files[0];
    // },
    // changeDialogStatus() {
    //   //出dialog
    //   this.$refs["ruleForm"].validate((valid) => {
    //     if (valid) {
    //       this.dialogVisible = true;
    //     } else {
    //       //                        this.$message({
    //       //                            message: "请填写完整信息",
    //       //                            type: "error",
    //       //                        });
    //     }
    //   });
    // },
    submitCheck(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid && this.uploadImg == true) {
          this.dialogVisible = true;
        } else if (this.uploadImg == false) {
          this.open1("请上传网上确认书", "error");
        } else {
            this.open1("请完整填写表单数据", "error");
        }
      });
    },
    // 上传网上确认书
    setSure(files){
      this.ruleForm.qrfile=files[0]
      // console.log(this.ruleForm.qrfile);
      if(this.ruleForm.qrfile){
        this.uploadImg = true
      }else{
        this.uploadImg = false
      }
      this.showImg = false
    },
  },
  components: {
    BaseUpload,
    upfile,
    examimg,
    uploads
  },
};
</script>
<style lang="less" scoped>
.btns {
  display: flex;
  justify-content: center;
  .el-button {
    margin: 0 20px;
  }
}

.upload {
  margin: 20px 0;
}

.box {
  display: flex;
  flex-direction: column;
  align-items: center;
  // margin-top: 100px;
  width: 100%;
  min-height: 800px;
  .tle {
    font-size: 24px;
    color: #000;
  }
  .el-form {
    width: 100%;
    .el-input {
      width: 80%;
    }
  }
  .must,
  .select {
    display: flex;
    position: relative;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 0 30px;
    margin-bottom: 80px;
    // width: 1000px;
    // border: 1px solid #bbbbbb;
    border-radius: 10px;
    .el-form-item {
      width: 680px;
    }
    .inline {
      display: flex;
      .el-form-item {
        margin: 0;
        width: 290px !important;
      }
    }
  }
  .must {
    margin-left: -262px;
    margin-bottom: 20px;
  }
  .line {
    width: calc(100% - 280px);
    margin: 10px auto;
    height: 1px;
    border-top: 1px dashed #d9d9d9;
  }
  .imgHint {
    margin: 5px;
    font-size: 12px;
    line-height: 17px;
    color: #f5222d;
  }
  .affirm {
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .input {
    width: 190px;
  }
  .upload {
    margin: 20px 0;
  }
  .type-number {
    width: 250px;
  }
  .inform {
    position: absolute;
    top: 10px;
    left: 260px;
    width: 500px;
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .informs {
    position: absolute;
    width: 500px;
    font-size: 12px;
    color: #a0a3a5;
    a {
      text-decoration: none;
      color: #3685ff;
    }
  }
  .inform {
    display: flex;
    align-items: center;
    position: absolute;
    top: 0;
    left: 80%;
    width: 300px;
    height: 32px;
    color: #F96900;
    font-size: 10px;
    line-height: 14px;
    img {
      margin: 11px;
    }
    .content {
      display: flex;
      flex-direction: column;
      .ts {
        text-indent: 3em;
      }
    }
  }
  .tle {
    list-style: none;
    margin: 40px 0 20px;
    font-size: 24px;
    & ~ .tle {
      color: #bbb;
    }
  }
  .hint {
    color: #F96900;
    background-color: #fff;
    .el-form-item__label {
      width: 150px;
    }
    img {
      width: 20px;
    }
  }
  .el-steps {
    width: 70%;
    height: 200px;
  }
  .el-button {
    //display: block;
    display: inline;
    margin: 0 20px;
    // background-color: #67c23a !important;
    // border-color: #67c23a !important;
  }

  .common .el-button {
    background-color: #fff !important;
    border-color: #bbb !important;
  }
}
.notice {
  color: #F96900;
  font-size: 12px;
}
.dialog-footer {
  display: flex;
  justify-content: space-between;
  color: #fff;
  .lan {
    background-color: #2c9dfc !important;
    border-color: #2c9dfc !important;
  }
}

.dialog /deep/ .el-form-item__label {
  width: 100px !important;
}

.dialog /deep/ .el-form-item__content {
  margin-left: 100px !important;
  display: flex;
  justify-content: left;
}

.dialog /deep/ .el-input {
  width: 250px;
}

.el-checkbox-group {
  line-height: 14px;
}

.is-checked /deep/ .el-radio__inner,
.is-checked /deep/ .el-checkbox__inner {
  border-color: #999999;
  background: #999999;
}

.el-radio /deep/ .el-radio__inner:hover {
  border-color: #999999 !important;
}

.is-checked /deep/ .el-radio__label,
.is-checked /deep/ .el-checkbox__label {
  color: #333;
}

.is-focus .el-checkbox__inner {
  border-color: #999999 !important;
}

.el-checkbox /deep/ .el-checkbox__inner:hover {
  border-color: #999999 !important;
}

.el-step__head.is-process {
  border-color: #f96900;
  color: #f96900 !important;
}

.hintMsg {
  /deep/ .el-dialog__header {
    display: flex;
    justify-content: center;
    font-weight: bold;
  }
  .dialog-footer {
    justify-content: center;
    .el-button {
      border-color: #2c9dfc !important;
      background: #2c9dfc !important;
    }
  }
}

/deep/ .el-dialog.el-dialog--center /deep/ {
    .el-dialog__header {
        padding: 0;
    }

    .el-dialog__body {
        padding: 20px 20px 50px;
    }

    .hint {
        color: #F96900;
        background-color: #fff;
        padding: 0;
        padding-bottom: 20px;
    }

    .el-button {
        margin: 0;
    }

    .el-form-item__label {
        width: 86px !important;
    }
}
#star{
  position: absolute;
  color: red;
  margin-left: -106px;
}
.exam-img{
  position: absolute;
  top: 0;
  left: 450px;
}
.img-inform{
  img{
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -140px;
    transform: translate(-50%,-50%);
  }
  span{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      white-space: nowrap;
      margin-left: -100px;
      width: 50px;
      color: #f96900;
  }
}
</style>
